﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CUREBusinessLogicLayer;
using System.Web.SessionState;
using System.Text.RegularExpressions;
using CUREDataAccessLayers;
using CUREBusinessLogicLayer.Harmful;
using CUREEntity.Harmful;

namespace CURE.Handler
{
    /// <summary>
    /// 不良胶F卡台账
    /// </summary>
    public class TBookHandler : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            string action = context.Request.Form["Action"];
            string formpage = context.Request.Form["Page"];

            #region 变量

            TBookModel tbModel = new TBookModel();
            TBookBll tbBll = new TBookBll();

            tbModel.ID = context.Request.Form["ID"];//编号（主键）
            tbModel.HID = context.Request.Form["HID"];//F卡信息ID
            tbModel.FID = context.Request.Form["FID"];//F卡号
            tbModel.Saccepter = context.Request.Form["Saccepter"];//受领担当
            tbModel.AcceptDate = context.Request.Form["AcceptDate"];//受领日

            tbModel.Stage = context.Request.Form["Stage"];//期别
            tbModel.Model = context.Request.Form["Model"];//型号
            tbModel.Category = context.Request.Form["Category"];//类别
            tbModel.Fdate = context.Request.Form["Fdate"];//F卡时间
            tbModel.Amount = context.Request.Form["Amount"];//数量（BT或包）

            tbModel.Jaccepter = context.Request.Form["Jaccepter"];//技术课判定担当
            tbModel.Sdate = context.Request.Form["Sdate"];//判定担当受领日期
            tbModel.Method = context.Request.Form["Method"];//处理方法
            tbModel.MDate = context.Request.Form["MDate"];//再处理日限
            tbModel.PDDate = context.Request.Form["PDDate"];//判定日

            tbModel.JCDate = context.Request.Form["JCDate"];//决裁日期
            tbModel.FHDate = context.Request.Form["FHDate"];//返回申请部门日期
            tbModel.PDSDate = context.Request.Form["PDSDate"];//判定书处理完成返回
            tbModel.BackDate = context.Request.Form["BackDate"];//返回日期
            tbModel.Result = context.Request.Form["Result"];//判定结果

            tbModel.Remarks = context.Request.Form["Remarks"];//备注
            tbModel.Recorder = context.Request.Form["Recorder"];//录入人
            tbModel.RecordDate = context.Request.Form["RecordDate"];//录入时间
            #endregion
            
            switch (action)
            {
                case "addTBook":
                    #region 添加技术判定书
                    if (tbBll.InsertBook(tbModel))
                    {
                        context.Response.Write(success("Harmful/"+formpage+".aspx"));
                    }
                    else 
                    {
                        context.Response.Write(failure(" 添加技术判定书失败！"));
                    }
                    break;
                    #endregion
                case "editTBook":
                    #region 修改技术判定书
                    if (tbBll.UpdateBook(tbModel))
                    {
                        context.Response.Write(success("Harmful/"+formpage+".aspx"));
                    }
                    else
                    {
                        context.Response.Write(failure(" 修改技术判定书失败！"));
                    }
                    break;
                    #endregion
                default:
                    break;
            }

        }

        #region 提示信息
        /// <summary>
        /// 操作失败(无参数)
        /// </summary>
        /// <returns></returns>
        public string failure()
        {
            return "{\"statusCode\":\"300\", \"message\":\"操作失败\"}";
        }
        /// <summary>
        /// 操作失败(有参数)
        /// </summary>
        /// <param name="str">错误提示</param>
        /// <returns></returns>
        public string failure(string str)
        {
            return "{\"statusCode\":\"300\", \"message\":\"操作失败!" + str + "\"}";
        }
        /// <summary>
        /// 操作失败(有参数)
        /// </summary>
        /// <param name="str">错误提示</param>
        /// <returns></returns>
        public string failure1(string str)
        {
            return "{\"statusCode\":\"300\", \"message\":\"" + str + "\"}";
        }
        /// <summary>
        /// 操作成功(无参数)
        /// </summary>
        /// <returns></returns>
        public string success()
        {
            return "{\"statusCode\":\"200\", \"message\":\"操作成功!\",\"callbackType\":\"closeCurrent\"}";
        }

        public string success1()
        {
            return "{\"statusCode\":\"200\", \"message\":\"操作成功!\"}";
        }

        /// <summary>
        /// 操作成功(有参数)
        /// </summary>
        /// <param name="str">信息</param>
        /// <param name="navTabId">页面指向</param>
        /// <returns></returns>
        public string success(string str, string navTabId)
        {
            return "{\"statusCode\":\"200\", \"message\":\"操作成功!" + str + "\",\"navTabId\":\"" + navTabId + "\"}";
        }
        public string success(string navTabId)
        {
            return "{\"statusCode\":\"200\", \"message\":\"操作成功!\",\"callbackType\":\"closeCurrent\",\"navTabId\":\"" + navTabId + "\"}";
        }
        #endregion

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}